
var __HbssClickUrl = 'http://localhost:81/map';//点击系统的根路径
var __HbssClickPage;//特定的点击分析页面

var __HbssReturnPage;//返回作记录的页面,这个需要更进一步扩展
var __HbssReturnType;//返回作记录的类型

if( __HbssClickPage == null )
{
	__HbssReturnType = 'common';
	__HbssReturnPage = __UrlGetPage( top.location.href,'common' );
}
else
{
	__HbssReturnType = 'click';
	if( __HbssClickPage != top.location.href )
	{
		__HbssReturnPage = null;
	}
	else 
	{	
		__HbssReturnPage = escape( __UrlGetPage( __HbssClickPage,'' ) );
	}
}
//alert(__HbssReturnPage);

function __UrlGetPage(url,rek)
{
	//通过URL返回一个特定的值
	var i=0,h;
	url = url.toLowerCase();
	if ( (i=url.indexOf("://")) < 0 ) return "";//本地文件不处理
	{
		h=url.substring(i+3,url.length);//处理"://"后面的
	}
	if( rek == 'common' )
	{
		if(h.indexOf("?") > 0)
			return h.substring(0,h.indexOf("?"));
			//默认不处理?号后面的包括参数
	}
	return h;	
}

if (document.addEventListener)
{     
	document.addEventListener("click", __HbssClickEvent, false); 
} 
else if (document.attachEvent)
{     
	document.attachEvent("onclick", __HbssClickEvent);
}

function __getScrollXY()
{
	var x = 0;var y = 0;
	if(document.body.scrollTop)
	{  
		x = document.body.scrollLeft; 
		y = document.body.scrollTop;
	}
	else
	{  
		x = document.documentElement.scrollLeft;  
		y = document.documentElement.scrollTop;
	}
	return {x:x,y:y};
}


function __HbssClickEvent(ev)
{ 
	if( __HbssReturnPage == null ) return '';
	
	//点击概率 0=100%;1=90%;...9=10%;10=0%;
	if(parseInt(Math.random()* 10) < 0 ) 
	return;    

	ev = ev || window.event;    
	var x = ev.clientX + __getScrollXY().x - document.getElementsByTagName("body")[0].offsetLeft;    
	var y = ev.clientY + __getScrollXY().y - document.getElementsByTagName("body")[0].offsetTop;    
	if (x < 0 || y < 0) return;    
	try 
	{        
		var s = document.createElement("script");
		s.type = "text/javascript";
		s.src = __HbssClickUrl + "/clickstat.php?pageid="+__HbssReturnPage+"&type="+__HbssReturnType+"&w="+screen.width+"&x="+x+"&y="+y;
		document.getElementsByTagName("head").item(0).appendChild(s);    
	}
	catch(e){}
}